<?php
/**
 * CEOfox
 *
 * @copyright  Copyright 2011-2012 CEOfox, Inc.
 * @license    http://ceofox.com/pages/license
 * @version    $Id: blocker.class.php 87083 2013-05-24 09:40:17 $
 * @author     CEOfox, Inc.
 */
?>
<?php
defined('PHPFOX') or exit('NO DICE!');

class Follow_Component_Block_Blocker extends Phpfox_Component
{ 
    public function process()
    {   
        Phpfox::isUser(true);
        $bIsCurrentUser = false; 
        $iPage = $this->getParam('page', 1);
        $iOffset = ($iPage - 1) * phpfox::getParam('follow.showeachtime');
        $bCanFollow = false;
        $aUser = $this->getParam('aUser');
        $sType = $this->getParam('type_id', 'user');
        if($sType == 'user')
        {
            if(!$aItem = $this->getParam('aUser'))
            {
                $aItem = Phpfox::getService('user')->get(Phpfox::getUserId());
                $bIsCurrentUser = true;
            }
        }
        else
        {
            if(!Phpfox::hasCallback($sType, 'getActivityFeed') || !$aParentModule = $this->getParam('aParentModule', false))
            {
                return false;
            }
            $aItem = Phpfox::callback($sType . '.getActivityFeed', $aParentModule, null, true);
            if($sType == 'pages')
            {
                if(Phpfox::getService('pages')->isAdmin($aParentModule['item_id']))
                {
                    $bIsCurrentUser = true;
                }
                else
                {
                    $sUrl = Phpfox::permalink($aParentModule['module_id'], $aParentModule['item_id']);
                    $this->url()->send($sUrl, null, Phpfox::getPhrase('follow.page_not_found'));
                }
            }
            else
            {
                if($aItem['user_id'] == Phpfox::getUserId())
                {
                    $bIsCurrentUser = true;
                }
            }
        }
        $aItem['item_id'] = $aItem[(($sType == 'pages') ? 'page': $sType).'_id'];        
        $aResult = array();
        $sKeyword = '';
        $iTotalBlocker = 0;
        $aBlockers = $this->getParam('aItems', array());
        
        if(!$sKeyword = $this->getParam('sKeyword'))
        {
            list($iTotalBlocker, $aBlockers) = Phpfox::getService('follow')->getBlocker($aItem[(($sType == 'pages') ? 'page': $sType).'_id'], $iOffset, phpfox::getParam('follow.showeachtime'), $sType, $sKeyword);
        }
        if(!empty($aBlockers))
        {
            foreach($aBlockers as $aBlocker)
            {
                $aResult[] = phpfox::getService('user')->get($aBlocker['user_id']);
            }
        }
        
        $this->template()->assign(array(
            'sType' => $sType,
            'iPage' => $iPage,
            'aItem' => $aItem,
            'sBlockType' => ($this->getParam('sBlockType') ? $this->getParam('sBlockType') : 'blocker'),
            'sKeyword' => $sKeyword,
            'aBlockers' => $aResult,
            'iCurrentBlocker' => isset($aBlockers) ? count($aBlockers) : 0,
            'iTotalBlocker' => ($this->getParam('iCnt') ? $this->getParam('iCnt') : $iTotalBlocker),
            'sFullControllerName'  => Phpfox::getLib('module')->getFullControllerName(),
        ));
      
    }
    public function clean()
    {        
        (($sPlugin = Phpfox_Plugin::get('follow.component_block_blocker_clean')) ? eval($sPlugin) : false);
    }
}

?>
